package com.cl.code.database.mybatis.module.page;

import com.github.pagehelper.PageHelper;
import lombok.Data;

/**
 * 分页参数
 *
 * @author chengliang
 * @since 1.0.0
 */
@Data
public class PageParam {

    /**
     * 页码
     */
    private Integer pageNumber = 1;

    /**
     * 每页大小
     */
    private Integer pageSize = 10;

    public PageParam() {
    }

    public PageParam(Integer pageNumber, Integer pageSize) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
    }

    public void startPage() {
        if (pageSize == null || pageSize < 1) {
            return;
        }
        if (pageNumber == null || pageNumber < 1) {
            return;
        }
        PageHelper.startPage(pageNumber, pageSize);
    }

    public static PageParam of(Integer pageNumber, Integer pageSize) {
        return new PageParam(pageNumber, pageSize);
    }

}
